/*
package com.pro01.backend.mapper;

import com.pro01.backend.pojo.EmailVerification;
import org.apache.ibatis.annotations.*;

@Mapper
public interface EmailVerificationMapper {

    // 插入验证码（如果邮箱已存在，则更新）
    @Insert("INSERT INTO email_verification (email, code, created_at) " +
            "VALUES (#{email}, #{code}, NOW()) " +
            "ON DUPLICATE KEY UPDATE code = VALUES(code), created_at = NOW()")
    int saveEmailCode(EmailVerification verification);

    // 查询验证码
    @Select("SELECT * FROM email_verification WHERE email = #{email}")
    EmailVerification getEmailCode(String email);

    // 删除验证码
    @Delete("DELETE FROM email_verification WHERE email = #{email}")
    int deleteEmailCode(String email);

    // 清除 10 分钟前的验证码（定时任务用）
    @Delete("DELETE FROM email_verification WHERE created_at < NOW() - INTERVAL 10 MINUTE")
    int deleteExpiredEmailCodes();
}
 */

package com.pro01.backend.mapper;

import com.pro01.backend.pojo.EmailVerification;
import org.apache.ibatis.annotations.*;

@Mapper
public interface EmailVerificationMapper {

    // 插入邮箱验证码
    //@Insert("INSERT INTO email_verification (email, code, created_at) VALUES (#{email}, #{code}, NOW())")
    //int saveEmailCode(EmailVerification emailVerification);
    // 插入验证码（如果邮箱已存在，则更新）
    @Insert("INSERT INTO email_verification (email, code, created_at) " +
            "VALUES (#{email}, #{code}, NOW()) " +
            "ON DUPLICATE KEY UPDATE code = VALUES(code), created_at = NOW()")
    int saveEmailCode(EmailVerification verification);

    // 查询最新的验证码
    @Select("SELECT * FROM email_verification WHERE email = #{email} ORDER BY created_at DESC LIMIT 1")
    EmailVerification getLatestCode(String email);

    // 删除已使用的验证码（防止重复注册）
    @Delete("DELETE FROM email_verification WHERE email = #{email}")
    int deleteEmailCode(String email);
}
